<template>
  <div><br>
        <el-form :model="formData"  label-width="80px">
            <el-form-item label="病人名字">
                <el-input :value="patient.name"></el-input>
            </el-form-item>
            <el-form-item label="医生名字">
                <el-input :value="doctor.docName"></el-input>
            </el-form-item>
            <el-form-item label="检查">
                <el-select  placeholder="检查" v-model="formData.projectId"  clearable="">
                    <!-- <el-option v-for="check in checks" :key="check.id" :label="check.pjName" :value="check.id"></el-option> -->
                    <el-option v-for="check in checks" :key="check.id" :label="`${check.pjName} —— ￥${check.pjPrice}`" :value="check.id"></el-option>
                </el-select>
            </el-form-item>

            <el-form-item>
                <!-- <el-button>打印</el-button> -->
            </el-form-item>
            <el-form-item>
                <el-button type="warning" size="mini" @click="closeDialogWithData">取消</el-button>
                <el-button type="primary" size="mini" @click="addCheckItem">确定</el-button>
            </el-form-item>
        </el-form>

        <span style="color: red;">{{ msg }}</span>
  </div>
</template>

<script>
export default {
    props: {
        caseId:{
            type: Number,
            required: true
        }
    },
    data(){
        return{
            formData:{},
            patient:{},
            doctor:{},
            checkItem:{},
            checks:[],
            msg:''
        }
    },
    methods:{
         //开检查和检查明细
         addCheckItem(){
            if(this.formData.projectId==null || this.formData.projectId==''){
                this.msg='请选择检查项目'
                return;
            }
            this.formData.patientId = this.patient.id;
            this.$axios.post("api/doctor/addCheck",this.formData)
            .then(res=>{
                if(res.data.code==200){
                    this.$message.success("开单成功")
                    this.closeDialogWithData()
                }
            })
        },
        //查找检查信息
        queryChecks(){
            this.$axios.get("api/doctor/queryChecks")
        .then(res=>{
            if(res.data.code==200){
                this.checks=res.data.data;
            }
        })
        },
        //查找医生信息
        queryDoctor(){
        this.$axios.get("api/doctor/queryDoctor")
        .then(res=>{
            if(res.data.code==200){
                this.doctor=res.data.data;
            }
        })
        },
        //查找病人信息
        queryPatient(){
            this.$axios.get("api/doctor/queryPatient/"+this.caseId)
            .then(res=>{
            if(res.data.code==200){ 
                this.patient=res.data.data;
                console.log(this.patient)
            }
        }) 
        },
        closeDialogWithData() {
            // 触发事件并传递数据给父组件
            this.$emit('closeDialog', this.caseId); // 替换 dataToPass 为你想要传递的数据
        }
    },
    created(){},
    mounted(){
        this.queryDoctor()
        this.queryPatient()
        this.queryChecks()
    }
}
</script>

<style>

</style>